﻿using System;
using System.Collections;
using System.Collections.Generic;
using TrueSync;
using Network;
[System.Serializable]
public class JumpHitState : StateBase//空中击退硬直
{
    public FP XTranslateLength;
    public FP XTranslateSpeed;

    LogicMoveComponent mMoveComponent;

    public override StateEnum StateName
    {
        get
        {
            return StateEnum.JumpHit;
        }
    }

    public override bool IsFinished()
    {
        return !mMoveComponent.IsHittingBack && mMoveComponent.Position.y <= 0;
    }

    public override void Enter(LogicEntity lEntity, StateBase lastState, object[] stateParams)
    {
        base.Enter(lEntity, lastState, stateParams);
        mMoveComponent = mLEntity.GetLogicComponent<LogicMoveComponent>();
        mMoveComponent.Hitback(XTranslateLength, -XTranslateSpeed * mMoveComponent.FaceDirection);
    }

    public override void Excute(FP deltaTime)
    {
        if (statusComponent.HP <= 0)
        {
            mLEntity.GetLogicComponent<LogicStateMachineComponent>().ChangeState(StateEnum.Dead);
            return;
        }

        if (statusComponent.Dizzy <= 0)
        {
            mLEntity.GetLogicComponent<LogicStateMachineComponent>().ChangeState(StateEnum.Dizzy);
            return;
        }

        if (IsFinished())
        {
            LogicStateMachineComponent stateMachineComponent = mLEntity.GetLogicComponent<LogicStateMachineComponent>();
            stateMachineComponent.ChangeState(StateEnum.Stand);
        }
    }

    public override void Exit()
    {
        mMoveComponent.HitbackFinish();
        mMoveComponent = null;
        base.Exit();
    }

    public override void OnStimulate(Stimulate stimulate)
    {
        LogicStateMachineComponent stateMachineComponent = mLEntity.GetLogicComponent<LogicStateMachineComponent>();
        switch (stimulate.StimulateType)
        {
            case StimulateTypeEnum.ThrowStimulate:
                stateMachineComponent.ChangeState(StateEnum.ThrowHit);
                break;
        }
    }

    public override void Deserialize(EByte ms)
    {
        base.Deserialize(ms);
        XTranslateLength = FP.FromRaw(ms.ReadLong());
        XTranslateSpeed = FP.FromRaw(ms.ReadLong());
    }

    public override void Serialize(EByte ms)
    {
        base.Serialize(ms);
        ms.WriteLong(XTranslateLength.RawValue);
        ms.WriteLong(XTranslateSpeed.RawValue);
    }
}
